package com.modules.login;

import com.base.activity.ActivityScope;
import com.base.mvp.BasePresenterImpl;
import com.face.gaoml.netlibrary.data.rusult.BaseSubscriber;
import com.face.gaoml.netlibrary.data.rusult.HttpResultFunc;
import com.modules.bean.User;

import javax.inject.Inject;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */
@ActivityScope
public class LoginPresenter extends BasePresenterImpl<LoginContract.View> implements LoginContract.Presenter{



    @Inject  //1 构造函数 提供支援 提供对象     2.注入构造器所需要的参数的依赖 （ 注入传递）
    public LoginPresenter() {
    }

    /**
     * 登录 请求
     *
     * @param name
     * @param pass
     */
    public void login(String name, String pass) {
        mRxManager.addSubscription(
                apiStores.login("86", name, pass)
                        .map(new HttpResultFunc<User>()),
                new BaseSubscriber<User>() {
                    @Override
                    public void onNext(User result) {
                        if (result != null) {
//                            getView().loginSucc(result);
//                            mvpView.Succ(result);
                        }
                    }
                }

        );
    }

    /**
     * 用户注册
     * @param phone_number
     * @param password
     */

    public void regit(String phone_number, String password){
        mRxManager.addSubscription(
                apiStores.regit("86", phone_number, password)
                        .map(new HttpResultFunc<User>()),
                new BaseSubscriber<User>() {
                    @Override
                    public void onNext(User result) {
                        if (result != null) {
//                            getView().registSucc(result);
//                            mvpView.Succ(result);
                        }
                    }
                }

        );
    }
}
